package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@Api(tags = "店铺相关接口")
@RequestMapping("/admin/shop")
public class ShopController {


    public static String KEY = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;


    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getStatus(){
        log.info("获取店铺状态");
        Integer shopStatus = (Integer)redisTemplate.opsForValue().get(KEY);
        System.out.println(shopStatus);
        return Result.success(shopStatus);
    }


    @PutMapping("/{status}")
    @ApiOperation("修改店铺状态")
    public Result updateStatus(@PathVariable Integer status){
        log.info("修改店铺状态：{}",status);
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }
}
